package edu.centenary.centenaryController;
public class BodyPart {
    //datamembers
	 public static final double FUZZINESS = 0.75;
	 /** Name of the limb*/
    private String bodyPart = null;
	 /** X coordinate of the limb as percieved by the robot's Victim Sensor */
    private double locationX = 0;
	 /** Y coordinate of the limb as percieved by the robot's Victim Sensor */
    private double locationY = 0;
	 /** Z coordinate of the limb as percieved by the robot's Victim Sensor */
    private double locationZ = 0;
	 private int group = 0;
	 private boolean dirty = false;
	 private int center = 0;
    /** The constructor method for BodyPart
	 * @param bodyPart Name of the limb
	 * @param locationX X coordinate of the limb as percieved by the robot's Victim Sensor
	 * @param locationY Y coordinate of the limb as percieved by the robot's Victim Sensor
	 * @param locationZ Z coordinate of the limb as percieved by the robot's Victim Sensor
	 */
    public BodyPart(String bodyPart, double locationX, double locationY, double locationZ) {
        this.bodyPart = bodyPart;
        this.locationX = locationX;
        this.locationY = locationY;
        this.locationZ = locationZ;
    }

    //methods
	 public String toString(){
	 	String a = "";
		a+= bodyPart + " " + locationX + " " + locationY + " " + locationZ;
		return a;
	 }
	 public double distance(BodyPart bp){
	 	double x = Math.sqrt(Math.pow((bp.locationX - this.locationX),2)+
		Math.pow((bp.locationY - this.locationY),2)+
		Math.pow((bp.locationZ - this.locationZ),2));
		return x;
	 }
	 /**
	 * Sets the body part name
	 * @param bodyPart Name of the limb
	 */
    public void setBodyPart(String bodyPart) {
        this.bodyPart = bodyPart;
    }
	 /**
	 * Gets the body part name
	 * @return Name of the limb
	 */
    public String getBodyPart() {
        return bodyPart;
    }
	 /**
	 * Sets limb's X coordinate
	 * @param locationX X coordinate of the limb as percieved by the robot's Victim Sensor
	 */
    public void setLocationX(double locationX) {
        this.locationX = locationX;
    }
	 /**
	 * Gets limb's X coordinate
	 * @return X coordinate of the limb as percieved by the robot's Victim Sensor
	 */
    public double getLocationX() {
        return locationX;
    }
	 /**
	 * Sets limb's Y coordinate
	 * @param locationY Y coordinate of the limb as percieved by the robot's Victim Sensor
	 */
    public void setLocationY(double locationY) {
        this.locationY = locationY;
    }
	 /**
	 * Gets limb's Y coordinate
	 * @return Y coordinate of the limb as percieved by the robot's Victim Sensor
	 */
    public double getLocationY() {
        return locationY;
    }
	 /**
	 * Sets limb's Z coordinate
	 * @param locationZ Z coordinate of the limb as percieved by the robot's Victim Sensor
	 */
    public void setLocationZ(double locationZ) {
        this.locationZ = locationZ;
    }
	 /**
	 * Gets limb's Z coordinate
	 * @return Z coordinate of the limb as percieved by the robot's Victim Sensor
	 */
    public double getLocationZ() {
        return locationZ;
    }
	 public boolean getDirty(){
	 	return dirty;
	 }
	 public void setDirty(boolean dirty){
	 	this.dirty = dirty;
	 }
	 public int getGroup(){
	 	return group;
	 }
	 public void setGroup(int group){
	 	if(this.group != group){	
			this.group = group;
			setDirty(true);
		}
	 }
	 public int getCenter(){
	 	return center;
	 }
	 public void setCenter(int center){
	 	this.center = center;
	 }
	 
	 /**
	 * A custom equals method used to ensure that the same body part isn't added to the array twice.  Accounts for in percieved body part location caused by sensor noise.
	 */
    public boolean equals(Object other) {
        if (other instanceof BodyPart) {
            BodyPart bp = (BodyPart)other;
            if (bodyPart.equals(bp.bodyPart) ) {
                if ( Math.sqrt(Math.pow((locationX - bp.getLocationX()), 2) + Math.pow((locationY - bp.getLocationY()), 2) + Math.pow((locationZ - bp.getLocationZ()), 2)) <	FUZZINESS) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

}